var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

// var publicPath = 'http://39.108.158.235/';
// if (__DEV__) {
//     publicPath = 'http://localhost:3000/'; // 确保图片地址引用有效。
// }
var hotMiddlewareScript = 'webpack-hot-middleware/client?reload=true';  //reload = true 参数，如果碰到不能hot reload的情况，就整页刷新。

var config = {
    entry: {
        'index': ['./routers', hotMiddlewareScript],
        // 'tinymce': './vendor/tinymce/js/tinymce/tinymce.min.js' // 不确定是否有用到
        // 'server': './server.js',
    },

    output: {
        path: path.resolve(__dirname, 'static'),
        filename: '[name].js',
        // publicPath: publicPath
    },
    devtool: 'source-map',

    // devServer: {
    //     inline: true,
    //     port: 3000
    // },

    module: {
        loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',

            query: {
                presets: ['es2015', 'react', 'stage-0']
            }
        },
        {
            test: /\.(less|css)$/,
            loader: ExtractTextPlugin.extract({ fallback: 'style-loader', use: ['css-loader', 'less-loader'] }) //'style-loader!css-loader'
        },

        {
            test: /\.(png|jpg)$/,
            loader: 'url-loader?name=[name].[ext]'
        },
        {
            test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            loader: "url-loader?limit=10000&mimetype=application/font-woff"
        },
        {
            test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
            loader: "file-loader"
        },
        ]
    },

    // resolve: {
    //     alias: {
    //         tinymce: 'vendor'
    //     }
    // },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),   // webpack-dev-middleware & webpack-hot-middleware 插件配置
        new webpack.NoEmitOnErrorsPlugin(),
        new ExtractTextPlugin("[name].css"), // 单独为页面引入css
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        }) //压缩代码
    ]
}

/** javascript related to entry will hot reload */
if (module.hot) {
    module.hot.accept();
}

module.exports = config;